package scclient

import (
	"context"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"grpc-common/search/types/search"
)

type (
	GetAlbumInfoByIdReq  = search.GetAlbumInfoByIdReq
	GetAlbumInfoByIdResp = search.GetAlbumInfoByIdResp
	OnSaleAlbumReq       = search.OnSaleAlbumReq
	OnSaleAlbumResp      = search.OnSaleAlbumResp
	DeleteAlbumReq       = search.DeleteAlbumReq
	DeleteAlbumResp      = search.DeleteAlbumResp
	GetAlbumChannelReq   = search.GetAlbumChannelReq
	GetAlbumChannelResp  = search.GetAlbumChannelResp
	AlbumInfoReq         = search.AlbumInfoReq
	AlbumInfoResp        = search.AlbumInfoResp
	KeyWordReq           = search.KeywordReq
	KeyWordResp          = search.KeywordResp
	FindAlbumInfoReq     = search.FindAlbumInfoReq
	FindAlbumInfoResp    = search.AlbumInfo
	UpdateRankingReq     = search.UpdateRankingReq
	UpdateRankingResp    = search.UpdateRankingResp
	Search               interface {
		GetAlbumPropertyValueInfoByTitle(ctx context.Context, in *GetAlbumInfoByIdReq, opts ...grpc.CallOption) (*GetAlbumInfoByIdResp, error)
		OnSaleAlbum(ctx context.Context, in *OnSaleAlbumReq, opts ...grpc.CallOption) (*OnSaleAlbumResp, error)
		DeleteAlbum(ctx context.Context, in *DeleteAlbumReq, opts ...grpc.CallOption) (*DeleteAlbumResp, error)
		GetAlbumChannel(ctx context.Context, in *GetAlbumChannelReq, opts ...grpc.CallOption) (*GetAlbumChannelResp, error)
		SearchAlbumInfo(ctx context.Context, in *AlbumInfoReq, opts ...grpc.CallOption) (*AlbumInfoResp, error)
		KeyWord(ctx context.Context, in *KeyWordReq, opts ...grpc.CallOption) (*KeyWordResp, error)
		FindAlbumInfo(ctx context.Context, in *FindAlbumInfoReq, opts ...grpc.CallOption) (*FindAlbumInfoResp, error)
		UpdateRanking(ctx context.Context, in *UpdateRankingReq, opts ...grpc.CallOption) (*UpdateRankingResp, error)
	}

	defaultSearch struct {
		cli zrpc.Client
	}
)

func (m *defaultSearch) UpdateRanking(ctx context.Context, in *UpdateRankingReq, opts ...grpc.CallOption) (*UpdateRankingResp, error) {
	client := search.NewLiveClient(m.cli.Conn())
	return client.UpdateRanking(ctx, in, opts...)
}

func (m *defaultSearch) FindAlbumInfo(ctx context.Context, in *FindAlbumInfoReq, opts ...grpc.CallOption) (*FindAlbumInfoResp, error) {
	client := search.NewLiveClient(m.cli.Conn())
	return client.FindAlbumInfo(ctx, in, opts...)
}

func (m *defaultSearch) KeyWord(ctx context.Context, in *KeyWordReq, opts ...grpc.CallOption) (*KeyWordResp, error) {
	client := search.NewLiveClient(m.cli.Conn())
	return client.KeyWord(ctx, in, opts...)
}
func (m *defaultSearch) SearchAlbumInfo(ctx context.Context, in *AlbumInfoReq, opts ...grpc.CallOption) (*AlbumInfoResp, error) {
	client := search.NewLiveClient(m.cli.Conn())
	return client.SearchAlbumInfo(ctx, in, opts...)
}

func (m *defaultSearch) GetAlbumChannel(ctx context.Context, in *GetAlbumChannelReq, opts ...grpc.CallOption) (*GetAlbumChannelResp, error) {
	client := search.NewLiveClient(m.cli.Conn())
	return client.GetAlbumChannel(ctx, in, opts...)
}

func (m *defaultSearch) GetAlbumPropertyValueInfoByTitle(ctx context.Context, in *GetAlbumInfoByIdReq, opts ...grpc.CallOption) (*GetAlbumInfoByIdResp, error) {
	client := search.NewLiveClient(m.cli.Conn())
	return client.GetAlbumPropertyValueInfoByTitle(ctx, in, opts...)
}

func (m *defaultSearch) OnSaleAlbum(ctx context.Context, in *OnSaleAlbumReq, opts ...grpc.CallOption) (*OnSaleAlbumResp, error) {
	client := search.NewLiveClient(m.cli.Conn())
	return client.OnSaleAlbum(ctx, in, opts...)
}

func (m *defaultSearch) DeleteAlbum(ctx context.Context, in *DeleteAlbumReq, opts ...grpc.CallOption) (*DeleteAlbumResp, error) {
	client := search.NewLiveClient(m.cli.Conn())
	return client.DeleteAlbum(ctx, in, opts...)
}

func NewSearch(cli zrpc.Client) Search {
	return &defaultSearch{
		cli: cli,
	}
}
